﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Biz;
using System.Data.Entity;

namespace BusinessLayer.Dal
{
    public class CategoryDal
    {
        DatabaseContext db;
        public CategoryDal(/* DatabaseContext db */)
        {
            this.db = DatabaseContext.DB;
        }
        public List<Category> GetAllCategory()
        {
            return db.Categories.Where(c=>c.IsDeleted==false).ToList();
        }
        public Category GetById(int id)
        {
            return db.Categories.Where(c => c.Id == id).First();
        }
        public int Insert(Category category)
        {
            db.Categories.Add(category);
            return db.SaveChanges();
        }

        public int Update(Category category)
        {
            db.Entry(category).State = EntityState.Modified;
            return db.SaveChanges();
        }

        public int Delete(Category category)
        {
            category.IsDeleted = true;
            db.Entry(category).State = EntityState.Modified;
            //db.Categories.Remove(category);
            return db.SaveChanges();
        }
    }
}
